<template>
	<view class="my-page">
		<view class="header">
			<view class="option-btns">
				<up-icon name="setting" size="48rpx" color="#fff"></up-icon>
			</view>
			<view class="user-header">
				<up-avatar :src="userInfo.avatar" class="avatar" size="64" @click="goToProfile"></up-avatar>
				<view class="user-info">
					<text class="nickname">{{ userInfo.nickname || '未设置昵称' }}</text>
					<text class="username">@{{ userInfo.username }}</text>
				</view>
			</view>
		</view>

		<view class="menu-list">
			<view class="menu-item">
				<text class="menu-label">我的订单</text>
				<text class="menu-arrow">></text>
			</view>
			<view class="menu-item">
				<text class="menu-label">收货地址</text>
				<text class="menu-arrow">></text>
			</view>
			<view class="menu-item">
				<text class="menu-label">客服中心</text>
				<text class="menu-arrow">></text>
			</view>
			<view class="menu-item">
				<text class="menu-label">关于我们</text>
				<text class="menu-arrow">></text>
			</view>
		</view>
	</view>
</template>

<script setup>
	import {
		useUserStore
	} from '/stores/user.js'
	import {
		onPullDownRefresh
	} from '@dcloudio/uni-app'

	const userStore = useUserStore()

	const userInfo = userStore.userInfo

	function goToProfile() {
		uni.navigateTo({
			url: '/pages/profiles/profiles'
		})
	}

	onPullDownRefresh(() => {
		if (userStore.getUserInfo()) {
			uni.stopPullDownRefresh()
			uni.showToast({
				title: '刷新成功',
				icon: 'success'
			})
		}
	})
</script>

<style lang="scss">
	.my-page {
		width: 100%;
	}

	.header {
		background: linear-gradient(135deg, #4CAF50 0%, #45a049 100%);
		padding: 30rpx 60rpx;

		.option-btns {
			display: flex;
			justify-content: flex-end;
			align-items: center;
			gap: 10rpx;
		}
	}

	.user-header {
		padding: 30rpx 0;
		display: flex;
		flex-direction: column;
		align-items: center;
		color: white;
	}

	.avatar {
		margin-bottom: 30rpx;
		border: 4rpx solid rgba(255, 255, 255, 0.3);
	}

	.user-info {
		display: flex;
		flex-direction: column;
		align-items: center;
	}

	.nickname {
		font-size: 38rpx;
		font-weight: bold;
		margin-bottom: 10rpx;
	}

	.username {
		font-size: 28rpx;
		opacity: 0.8;
	}

	.menu-list {
		margin-top: 40rpx;
		display: flex;
		flex-direction: column;
		gap: 10rpx;
	}

	.menu-item {
		margin: 0 30rpx 2rpx;
		padding: 35rpx 30rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;
		border-radius: 10rpx;
		border: 1px solid rgba(128, 128, 128, 0.1);
		box-shadow: 0 2rpx 10rpx rgba(0, 0, 0, 0.05);
	}

	.menu-item:last-child {
		border-radius: 10rpx;
	}

	.menu-label {
		font-size: 32rpx;
		color: #333;
	}

	.menu-arrow {
		font-size: 32rpx;
		color: #ccc;
	}
</style>